package m.jclecai.com.activity;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import m.jclecai.com.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.adapter.IndicatorAdapter;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.fragment.RegisterOneFragment;
import m.jclecai.com.fragment.RegisterTowFragment;
import m.jclecai.com.listener.Callback;

public class NewlyRegisterActivity extends BaseActivity {

    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.pager)
    ViewPager pager;

    private List<Fragment> fragmentList;
    private static final String[] TITLE = new String[]{"手机号注册", "普通注册"};

    @Override
    public int getContentView() {
        return R.layout.activity_newly_register;
    }

    @Override
    public void initView() {
        leftOptionText("");
        rightOptionText("登录");
        setTitle("免费注册");
        tablayout.setTabMode(TabLayout.MODE_FIXED);
        tablayout.setupWithViewPager(pager);
        pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout));
        fragmentList = new ArrayList<>();
        RegisterTowFragment registerTowFragment = new RegisterTowFragment();
        RegisterOneFragment registerOneFragment = new RegisterOneFragment();
        fragmentList.add(registerTowFragment);
        fragmentList.add(registerOneFragment);
        tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition()) {
                    case 0://手机号注册
                        break;
                    case 1://普通注册
                        break;
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        IndicatorAdapter indicatorAdapter = new IndicatorAdapter(getSupportFragmentManager(), TITLE, fragmentList);
        pager.setAdapter(indicatorAdapter);
    }

    @OnClick(R.id.tv_right_option)
    void login(){
        checkLogin(new Callback(){
            @Override
            public void callbackSuccess() {
                super.callbackSuccess();
                setResult(RESULT_OK);
                finish();
            }

            @Override
            public void callbackField() {
                super.callbackField();
                finish();
            }
        });
    }
}
